package com.zzz.web.daoimpl;

import com.zzz.web.Data.RSSI;
import com.zzz.web.dao.RssiDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class RssiDaoIpml implements RssiDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<RSSI> all() {
        String sql = "select * from the_data_of_finger_point";
        List<RSSI> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<RSSI>(RSSI.class));
        return query;
    }


    @Override
    public void replace(RSSI rssi) {
        String sql = "REPLACE INTO the_data_of_finger_point"
                + " VALUES (?,?,?,?,?,?,?,?)";
        Object[] args = new Object[]{
                rssi.getNumber(),
                rssi.getFrequency(),
                rssi.getAP1MAC(),
                rssi.getAP1RSSI(),
                rssi.getAP2MAC(),
                rssi.getAP2RSSI(),
                rssi.getAP3MAC(),
                rssi.getAP3RSSI()};

        jdbcTemplate.update(sql, args);
    }

    @Override
    public void updateFrequency(int number) {

    }

    @Override
    public void test() {
        System.out.println("test");
    }
}
